<template>
	<view class="box">
		<!-- 标签栏 -->
		<view class="tab">
			<u-tabs :list="list1" @click="clicks" lineColor="#109C7A" :current="active" :activeStyle="{
						color: '#333',
						fontWeight: 'bold'
					}" :inactiveStyle="{
						color: '#999',
					}"></u-tabs>
		</view>
		<!-- 空列表 -->
		<view class="none" v-if="!list.length">
			<view class="none-img f-w">
				<image src="https://jw.xzsw2021.com/static/order/icon_199@2x.png" mode=""></image>
			</view>
			<view class="none-name f34 bold">暂时没有任何订单</view>
			<view class="none-desc f26 c666">赶快去下单吧</view>
			<view class="none-btn" @click="goHome">去首页逛逛</view>
		</view>
		<!-- 订单列表 -->
		<view class="content" v-else>
			<view class="card" v-for="(item,index) of list" :key="index" @click="goDetail(index,item.group_order_id)"
				v-if="!item.orderList[0].groupUser || (item.orderList[0].groupUser && item.orderList[0].groupUser.groupBuying.status == 10)">
				<!-- 名字状态 -->
				<view class="one fw-bt f28">
					<view class="title" style="font-size: 30rpx;">
						{{item.orderList[0].merchantField.marketField.mar_name}}
					</view>
					<view class="" v-if="item.orderList[0].activity_type == 1">
						秒杀单
					</view>
					<view class="" v-if="item.orderList[0].activity_type == 4">
						拼团单
					</view>
					<view class="state red" v-if="item.is_del">
						已删除
					</view>
					<view class="state red" v-else-if="item.paid==1">{{getState(item.task_status,item.cancel_examine)}}
					</view>
					<view class="state red" v-else-if="item.paid!=1 && (item.task_status == 6)">
						已取消
					</view>
					
					<view class="state red" v-if="item.paid!=1 && (item.is_del == 0 && item.task_status != 6)">待支付
					</view>
				</view>
				<view class="" style="font-size: 24rpx;color: #666;margin: 10rpx 0;">
					{{$u.timeFormat(item.create_time, 'yyyy年mm月dd日  hh:MM')}}
				</view>
				<!-- 待支付描述 -->
				<view class="two" v-if="item.paid!=1 && (item.is_del == 0 || item.task_status != 6)">
					<view class="f24">待支付</view>
					<view class="c999 f22">请在倒计时内尽快完成支付，超时订单将自动取消</view>
				</view>
				<!-- 支付时间 -->
				<view class="three f22 c999" v-if="item.carete_time">{{item.carete_time}}</view>
				<!-- 商品信息 -->
				<view class="four fw-bt">
					<view class="goods-img f-w">
						<view class="f-w">
							<view class="goods-img2 f-w">
								<image :src="item.goods[0].cart_info.productAttr.image" mode=""></image>
							</view>
							<view class="goods-img2 f-w" v-if="item.goods.length>1">
								<image :src="item.goods[1].cart_info.productAttr.image" mode=""></image>
							</view>
							<view class="goods-img2 f-w" v-if="item.goods.length>2">
								<image :src="item.goods[2].cart_info.productAttr.image" mode=""></image>
							</view>
							<view class="goods-img2 f-w" v-if="item.goods.length>3">
								<image :src="item.goods[3].cart_info.productAttr.image" mode=""></image>
							</view>
						</view>
						<!-- 三点 -->
						<view class="dot f-w" v-if="item.goods.length>4">
							<image src="https://jw.xzsw2021.com/static/order/icon_296@2x.png" mode=""></image>
						</view>

					</view>
					<!-- 价格数量 -->
					<view class="four-r">
						<view class="price f24 red">￥<text class="f36 bold">{{item.pay_price}}</text></view>
						<view class="num f22">共{{item.total_num}}件</view>
					</view>
				</view>
				<!-- 取消原因 -->
				<view class="two" v-if="item.cancel_reason">
					<view class="f24">{{item.cancel_reason}}</view>
				</view>
				<!-- 操作按钮 -->
				<view class="five f-w">
					<!-- item.paid==1 -->
					<!-- "task_status": 1,//任务状态 1待帮买 2帮买中 3 待配送 4配送中 5配送完成 -->
					<!-- 更多 -->
					<!-- <view class="more" v-if="item.task_status==5">
						<view @click.stop="openMore(index)">更多</view>
						<view class="sanjiao" v-if="item.show_more"></view>
						<view class="more2" v-if="item.show_more">
							<view @click.stop="applyTicket(index)" v-if="!item.is_kp">申请开票</view>
							<view @click.stop="ticketHistory(item.id)" v-else>开票历史</view>
							<view @click.stop="delOrder(item.id)">删除订单</view>
						</view>
					</view> -->
					<view class="more" v-if="item.task_status==5&&item.paid==1">
						<view @click.stop="openMore(index)" v-if="!item.IsOrderAllRefund">更多</view>
						<view class="sanjiao" v-if="item.show_more"></view>
						<view class="more2" v-if="item.show_more">
							<view @click.stop="ticketHistory(item.id)" v-if="item.is_receipt_apply==1">开票历史
							</view>
							<view @click.stop="applyTicket(index)" v-else>申请开票</view>
							<view @click.stop="delOrder(item)">删除订单</view>
						</view>
					</view>
					<!-- <view @click.stop="cancelOrder(index)"
						v-if="item.paid!=1&&(item.task_status==1||item.task_status==2||item.task_status==3)">取消订单</view> -->
					<view @click.stop="updateAddressOrder(item.group_order_id)"
						v-if="item.is_del !=1 && item.task_status ==1">
						修改地址
					</view>
					<!-- <view @click.stop="userCancelGroupOrder(item)" v-if="item.is_del !=1 && item.task_status <= 3 ">取消订单 -->
					<view @click.stop="cancelOrder(index)" v-if="item.is_del !=1 && item.task_status <= 3 ">
						取消订单
					</view>
					<view @click.stop="updateDateOrder(item.group_order_id)"
						v-if="item.is_del !=1 &&item.task_status ==1">修改配送时间</view>
					<view @click.stop="goPayOrder(index)" class="state1" v-if=" item.paid!=1 && (item.is_del==0 &&
						item.task_status !=6)">
						去支付{{(item.m<10?'0'+item.m:item.m)+':'+(item.s<10?'0'+item.s:item.s)}}</view>

					<view @click.stop="reminderOrder2(item.group_order_id)" :class="item.psy?'state3':'state2'"
						v-if="item.task_status==3&&item.is_urge == 0&&item.paid==1 &&item.is_del==0">
						催单</view>
					<view @click.stop="cuidan22" :class="item.psy?'state3':'state2'"
						v-if="item.task_status==3&&item.is_urge == 1&&item.paid==1 &&item.is_del==0">
						催单</view>
					<view @click.stop="goEvaluation(item.id)" v-if="item.task_status==5&&item.status == 2">去评价</view>
					<view @click.stop="goAfterSales(item)"
						v-if="item.task_status==5&&item.paid==1 && !item.IsOrderAllRefund">申请售后</view>
					<!-- <view @click.stop="delOrder(item)" v-if="item.task_status==6&&item.paid==1">删除订单</view> -->
					<view @click.stop="delOrder(item)" v-if="item.task_status==6">删除订单</view>
					<view @click.stop="againOrder(item)" class="state2"
						v-if="(item.task_status==6||item.task_status==5)">再来一单
					</view>
				</view>
			</view>
		</view>
		<!-- 透明盒子-取消更多用 -->
		<view class="mask" @click="cancelMore" v-if="is_mask"></view>
		<!-- 配送时间弹窗 -->
		<uni-popup ref="popup3" type="bottom">
			<view class="pop3">
				<!--  -->
				<view class="pop3-close f-w" @click="pop3Close">
					<image src="https://jw.xzsw2021.com/static/order/icon_200@2x.png" mode=""></image>
				</view>
				<view class="pop3-title tr f30">
					配送时间
				</view>
				<!-- 内容区 -->
				<view class="pop3-box flex">
					<view class="pop3-left">
						<view v-for="(item,index) of date_list" :key="index" class="tr"
							:class="activeT===index?'green2':''" @click="checkDate(index)">{{item}}</view>
					</view>
					<view class="pop3-right">
						<view class="aa fw-bt" v-for="(item,index) of times_list" :key="index"
							@click="chooseTimes(index)">
							<view :class="active2===index?'green2':''">{{item.tips}}{{item.start}}-{{item.end}}</view>
							<view class="pop3-img" v-if="active2==index">
								<image src="https://jw.xzsw2021.com/static/order/icon_149@2x.png" mode=""></image>
							</view>
						</view>
					</view>
				</view>
			</view>
		</uni-popup>
		<!-- 支付弹窗 -->
		<uni-popup ref="popup4" type="bottom" :isMaskClick="false">
			<view class="pop4">
				<view class="pop4-close f-w" @click="pop4Close">
					<image src="https://jw.xzsw2021.com/static/order/icon_200@2x.png" mode=""></image>
				</view>
				<view class="pop4-title f30 bold tr" v-if="choosecancelitem.orderList.length > 1">
					以下订单需要一起付款
				</view>
				<view class="pop4-desc tr" v-if="choosecancelitem.orderList.length > 1">由于以下订单共享优惠，需要一起付款</view>
				<view class="pop4-list">
					<view class="fw-bt" v-for="(item,index) of choosecancelitem.orderList" :key="index">
						<view class="f28">
							<view>{{item.merchantField.mer_name}}</view>
							<view>(共{{item.total_num}}件)</view>
						</view>
						<view class="orange">￥<text class="f34">{{choosecancelitem.pay_price}}</text></view>
					</view>
				</view>
				<!-- 按钮 -->
				<view class="pop4-btn f-w">
					<view class="p41" @click="pop4Close">取消</view>
					<view class="p41" @click="paychoose">付款</view>
				</view>
			</view>
		</uni-popup>
		<!-- 支付弹窗 -->
		<uni-popup ref="popup5" type="bottom">
			<view class="pop4">
				<view class="pop4-close f-w" @click="()=>{this.$refs.popup5.close()}">
					<image src="https://jw.xzsw2021.com/static/order/icon_200@2x.png" mode=""></image>
				</view>
				<view class="pop4-title f30 bold tr">
					以下订单需要一起取消
				</view>
				<view class="pop4-desc tr">由于以下订单共享优惠，需要一起取消</view>
				<view class="pop4-list">
					<view class="fw-bt" v-for="(item,index) of choosecancelitem.orderList" :key="index">
						<view class="f28">
							<view>{{item.merchantField.mer_name}}</view>
							<view>(共{{item.total_num}}件)</view>
						</view>
						<view class="orange">￥<text class="f34">{{item.pay_price*1}}</text></view>
					</view>
				</view>
				<!-- 按钮 -->
				<view class="pop4-btn f-w">
					<view class="p41" @click="pop5Sure">确认取消</view>
					<view class="p41" @click="()=>{this.$refs.popup5.close()}">我再想想</view>
				</view>
			</view>
		</uni-popup>
		<!-- 取消原因弹窗 -->
		<uni-popup ref="popup6" type="center" :isMaskClick="false">
			<view class="pop6">
				<view class="pop6-title f30  tr">
					请选择取消订单原因
				</view>
				<view class="pop6-list">
					<u-radio-group v-model="radiovalue1" placement="column" iconPlacement="right" @change="groupChange">
						<u-radio :customStyle="{marginBottom: '45rpx'}" v-for="(item, index) in radiolist1" :key="index"
							:label="item.name" :name="item.name" labelColor="#333" iconSize="15" activeColor="#22B591">
						</u-radio>
					</u-radio-group>
				</view>
				<view class="pop6-btn bold f28 tr f-w">
					<view class="c999" @click="pop6Sure">确认取消</view>
					<view class="red" @click="pop6Close">我再想想</view>
				</view>
			</view>
		</uni-popup>
		<!-- 催单弹窗 -->
		<uni-popup ref="popup7" type="center" :isMaskClick="false">
			<view class="pop7">
				<view class="pop7-img f-w">
					<image src="https://jw.xzsw2021.com/static/big/icon_208@2x.png" mode=""></image>
				</view>
				<!--  -->
				<view class="tr">
					<!-- <view class="pop7-title f36 bold">请您耐心等待</view> -->
					<view class="pop7-title f36 bold">{{cuifotitle}}</view>
					<view class="pop7-desc f24 c666">{{cuifocontent}}</view>
					<!-- <view class="pop7-desc f24 c666">商品正在配货中</view> -->
					<view class="pop7-btn" @click="pop7Close">知道了</view>
				</view>
			</view>
		</uni-popup>
		<!-- 催单弹窗 -->
		<uni-popup ref="popup22" type="center" :isMaskClick="false">
			<view class="pop7">
				<view class="pop7-img f-w">
					<image src="https://jw.xzsw2021.com/static/big/icon_208@2x.png" mode=""></image>
				</view>
				<!--  -->
				<view class="tr">
					<view class="pop7-title f36 bold">请您耐心等待</view>
					<!-- 	<view class="pop7-title f36 bold">{{cuifotitle}}</view>
					<view class="pop7-desc f24 c666">{{cuifocontent}}</view> -->
					<view class="pop7-desc f24 c666">商品正在配货中</view>
					<view class="pop7-btn" @click="pop7Close">知道了</view>
				</view>
			</view>
		</uni-popup>

	</view>
</template>

<script>
	import {
		againApi,
		orderCheckApi,
		getOrderDeliveryTimeConfigApi,
		userDeleteGroupOrderApi
	} from '@/api/order.js'
	import {
		getCartApi
	} from '@/api/cart.js'
	import Cache from '@/util/cache.js'
	export default {
		data() {
			return {
				cuifocontent: '',
				cuifotitle: '',
				address: '',
				closetime: '',
				changeaddr: false,
				activeT: 0,
				chooseid: '',
				orign: '', //用于满汉全席任务
				active: 0, //
				is_mask: false, //
				cancellist: [],
				list1: [{
					name: '全部',
				}, {
					name: '待支付',
				}, {
					name: '待配送'
				}, {
					name: '配送中'
				}, {
					name: '已完成'
				}, {
					name: '已取消'
				}, ], //标签
				list: [], //订单列表
				temp: null, //倒计时初始
				date_list: ['今天', '明天'], //
				active2: 0, //
				order: {
					end_time: '2022-02-15 14:37',
					time: '',
				},
				times_list: [{
						tips: '立即送达',
						start: '10:00',
						end: '12:00'
					},
					{
						tips: '',
						start: '12:00',
						end: '14:00'
					},
					{
						tips: '',
						start: '14:00',
						end: '16:00'
					},
					{
						tips: '',
						start: '16:00',
						end: '18:00'
					},
					{
						tips: '',
						start: '18:00',
						end: '20:00'
					},
					{
						tips: '',
						start: '20:00',
						end: '22:00'
					}
				], //送达时间列表
				// 基本案列数据
				radiolist1: [{
						name: '商品无货',
						disabled: false
					},
					{
						name: '发货时间问题',
						disabled: false
					},
					{
						name: '不想要了',
						disabled: false
					}, {
						name: '商品错选/多选',
						disabled: false
					},
					{
						name: '地址信息填写错误 ',
						disabled: false
					},
					{
						name: '价格贵了',
						disabled: false
					},
					{
						name: '没用/少用/错用优惠',
						disabled: false
					},
					{
						name: '其他',
						disabled: false
					}
				], //取消原因数据
				// u-radio-group的v-model绑定的值如果设置为某个radio的name，就会被默认选中
				radiovalue1: '商品无货',
				choosecancelitem: '',
			}
		},
		onLoad(options) {
			console.log(options);
			if (options.type) {
				this.active = options.type * 1
				console.log(this.active);
			}
			if (options.orign) {
				this.orign = options.orign
			}
			// this.getOrderCountdown()
			this.timer()
			this.getcancellist()
		},
		destroyed() { //切记页面销毁需要销毁
			clearInterval(this.temp);
			console.log('销毁', this.temp);
		},
		onReachBottom() {
			this.getlist(this.page + 1)
		},
		onShow() {
			if (this.changeaddr && this.address && this.chooseid) {
				this.getupdateAddressOrder()
			} else {
				this.page = 1
				this.list = []
				this.getlist(this.page)
			}
			this.getOrderTimes()
		},
		onHide() {
			this.endInter()
		},
		onUnload: function() {
			this.endInter()
		},

		methods: {
			getOrderTimes() { //配送时间走配置
				getOrderDeliveryTimeConfigApi().then(res => {
					this.times_list = res.data
				}).catch(err => {

				})
			},

			/**
			 * 用户取消已支付订单
			 * @param {Object} gorupOrder
			 */
			userCancelGroupOrder(gorupOrder) {
				console.log(gorupOrder)

			},
			cuidan22() {
				this.$refs.popup22.open()
			},
			endInter: function() {

				let {
					list
				} = this;
				list.forEach((v) => {

					clearInterval(v.timer);

				});

			},
			timeCountDown() {
				let list = this.list

				list.forEach((v) => {

					// 开定时器时先关闭定时器
					if (v.timer) {
						clearInterval(v.timer);
					}

					v.timer = setInterval(() => {
						v.endtime = v.endtime - 1000

						if (v.ed && v.endtime <= 0) {
							v.d = 0
							v.h = 0
							v.m = 0
							v.s = 0
							if (v.timer) {
								// 自动完成这里造成了死循环
								clearInterval(v.timer);
								// this.completeOrder(v.order_id, v);
							} // 刷新进行中			
							this.page = 1
							this.list = []
							this.getlist(this.page)


						} else {

							v.d = Math.floor(v.endtime / 1000 / 60 / 60 / 24);
							v.h = Math.floor(v.endtime / 1000 / 60 / 60 % 24);
							v.m = Math.floor(v.endtime / 1000 / 60 % 60);
							v.s = Math.floor(v.endtime / 1000 % 60);
						}

						// this.list = list

						// this.$forceUpdate()
					}, 1000);
				});
			},
			// 改变地址
			getupdateAddressOrder() {
				uni.showLoading({
					mask: true,
					title: "地址修改中"
				})
				this.$request('order/change_address', {
					group_order_id: this.chooseid,
					address_id: this.address.address_id
				}).then(res => {
					this.chooseid = ''
					this.address = ''
					this.changeaddr = false
					this.page = 1
					this.list = []
					this.getlist(this.page)
					uni.hideLoading()


				})

			},
			getcancellist() {
				this.$request('order/refund_message', {}, 'GET').then(res => {
					if (res.status == 200) {
						let arr = []
						this.radiovalue1 = res.data[0]
						res.data.forEach(item => {
							arr.push({
								disabled: false,
								name: item
							})
						})
						this.radiolist1 = arr

					}
				})
			},
			getDay(day, hours) {
				var today = new Date()
				var targetday = today.getTime() + 1000 * 60 * 60 * 24 * day + hours
				today.setTime(targetday)
				var tYear = today.getFullYear()
				var tMonth = today.getMonth()
				var tDate = today.getDate()
				tMonth = this.doHandleMonth(tMonth + 1)
				tDate = this.doHandleMonth(tDate)
				return tYear + '-' + tMonth + '-' + tDate
			},
			doHandleMonth(month) {
				var m = month
				if (month.toString().length === 1) {
					m = '0' + month
				}
				return m
			},
			// 切换nav
			clicks(item) {
				this.page = 1
				this.list = []
				this.active = item.index
				this.getlist(this.page)
			},
			formatDate(now) {
				var year = now.getFullYear();
				var month = now.getMonth() + 1;
				var date = now.getDate();
				var hour = now.getHours();
				var minute = now.getMinutes();
				var second = now.getSeconds();
				minute = minute >= 10 ? minute : '0' + minute
				second = second >= 10 ? second : '0' + second
				hour = hour >= 10 ? hour : '0' + hour
				return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
			},
			getlist(e) {
				let task_status
				if (this.active == 1 || this.active == '0') {
					task_status = ''
				} else {
					task_status = this.active + 1
				}
				let data = {
					task_status,
					page: e,
					paid: this.active == 1 ? 0 : 999,
					limit: 10,
				}
				uni.showLoading({
					mask: true
				})
				this.$request('order/group_order_list', data, 'GET').then(res => {
					if (res.status == 200) {
						let closetime = res.data.close_time
						this.closetime = res.data.close_time
						uni.hideLoading()
						res.data.list.forEach(item => {
							item.create_time = (new Date(item.create_time).getTime()) / 1000
							item.endtime = (item.create_time * 1000 + (closetime * 60 * 1000) -
								new Date().getTime())
							if (item.endtime > 0) {
								item.ed = true
							}


							item.is_kp = false
							item.show_more = false
							let arr = []
							item.orderList.forEach(item2 => {
								arr = arr.concat(item2.orderProduct)
							})
							item.goods = arr
						})
						if (e == 1) {
							this.list = res.data.list
						} else {
							if (res.data.list.length == 0) {
								uni.showToast({
									title: "暂无更多",
									icon: "none"
								})
								return
							}
							let list = this.list
							list = [...list, ...res.data.list]
							this.list = list
							this.page = e
						}
						this.timeCountDown()
					}


				})
			},
			// 去首页
			goHome() {
				uni.switchTab({
					url: '/pages/index/index'
				})
			},
			// 订单状态
			getState(num, cancel_examine) {
				if (num == 1) {
					return '待帮买'
				} else if (num == 2) {
					return '帮买中'
				} else if (num == 3) {
					return '待配送'
				} else if (num == 4) {
					return '配送中'
				} else if (num == 5) {
					return '配送完成'
				} else if (num == 6) {
					let txt = ''
					if (cancel_examine == 1) {
						txt = '审核中'
					}
					if (cancel_examine == 2) {
						txt = '成功'
					}
					if (cancel_examine == 3) {
						txt = '失败'
					}

					return '取消' + txt
				} else {
					return ''
				}
			},
			timer() { //页面多个定时器 //主要逻辑都在这页面更新
				let _that = this;
				// 检测一下是否有倒计时订单，没有就不执行后面
				let go = _that.list.some((item) => item.aa);
				console.log('qe', go);
				this.temp = setInterval(() => {
					_that.list.forEach((item, index) => {
						item.djs = this.getOrderCountdown(item.time1);
						_that.$set(_that.list, item.djs, this.getOrderCountdown(item.time1));
					})
				}, 1000)
			},
			// 取消支付时间计算
			getOrderCountdown(value = '2022-02-15 09:40', index) {
				// 倒计时=失效时间-当前时间
				let m = 0,
					s = 0;
				let Overtime = new Date(value.replace(/-/g, "/"));
				let currentDate = new Date(); //获取当前时间
				let disDate = (Overtime - currentDate); //相差时间毫秒数
				if (disDate < 0) {
					return false;
					// 发送请求取消订单
				}
				// 剩余分钟
				m = Math.floor(disDate / 1000 / 60);
				s = Math.floor(disDate / 1000 % 60);
				m = m < 10 ? ("0" + m) : m;
				s = s < 10 ? ("0" + s) : s;
				return m + ':' + s
			},
			// 订单详情
			goDetail(index, id) {
				this.list[index].show_more = false;
				let item = this.list[index]
				let task_status = ''
				if (item.task_status == 6) {
					task_status = 6
				}
				if(item.is_del){
					return;
				}
				if (item.paid != 1 && item.task_status == 6) {
					// uni.showToast({
					// 	title: "该订单已经取消",
					// 	icon: "none"
					// })
					console.log("????")
					// return
				}
				console.log('详情');
				uni.navigateTo({
					// url: '' +  + '&' + 、
					url: `/pages/client/order/order-detail/order-detail?id=${id}&closetime=${this.closetime}&task_status=${task_status}`
				})
				// uni.navigateTo({
				// 	url: '/pages/client/order/order-detail/order-detail?id=' + id + '&closetime=' + this.closetime
				// })
			},
			// 取消订单
			cancelOrder(index) {
				let _this = this;
				let list = this.list
				this.choosecancelitem = list[index]
				uni.showModal({
					content: '确认取消此订单吗？',
					confirmColor: '#F31E1E',
					success(res) {
						if (res.confirm) {
							console.log('取消订单');
							_this.$refs.popup5.open()
						}
					}
				})
				console.log('取消订单');

			},
			goPayOrder(index) {
				let _this = this;
				let list = this.list
				this.choosecancelitem = list[index]
				console.log(this.choosecancelitem.pay_price)
				console.log(this.choosecancelitem.orderList.length)
				uni.showModal({
					content: '确认支付',
					confirmColor: '#F31E1E',
					success(res) {
						if (res.confirm) {

							_this.$refs.popup4.open()
						}
					}
				})
			},
			// 确认取消
			pop5Sure() {
				this.$refs.popup5.close();
				this.$refs.popup6.open();
			},
			// 确认取消订单原因
			pop6Sure() {
				this.$refs.popup6.close();
				uni.showLoading({
					mask: true,
					title: "取消中"
				})
				this.$request('order/cancel/' + this.choosecancelitem.group_order_id, {
					reason: this.radiovalue1
				}).then(res => {
					if (res.status == 200) {
						uni.hideLoading()

						this.$showToast('取消成功')
						this.page = 1
						this.choosecancelitem = ''
						this.radiovalue1 = ''
						this.getlist(this.page)
					}
				})


			},
			// 关闭取消订单原因弹窗
			pop6Close() {
				this.$refs.popup6.close();
			},
			groupChange(n) {
				console.log('groupChange', n);
			},
			// 删除订单
			delOrder(item) {
				console.log(item)
				let This = this
				uni.showModal({
					content: '确认删除此订单吗？',
					confirmColor: '#F31E1E',
					success(res) {
						if (res.confirm) {
							userDeleteGroupOrderApi(item.group_order_id).then(res => {
								// This.$showToast(res.message)
								This.getlist(1)
							}).catch(err => {
								This.$showToast(err.message)
							})
						}
					}
				})
			},
			// 修改地址
			updateAddressOrder(id) {
				let that = this
				this.chooseid = id
				uni.showModal({
					content: '确认修改地址吗',
					confirmColor: '#F31E1E',
					success(res) {
						if (res.confirm) {
							that.changeaddr = true
							uni.navigateTo({
								url: '/pages/client/address-choose/address-choose?orgin=1'
							})
						}
					}
				})



			},
			// 去支付
			// goPayOrder(id) {
			// 	console.log('去支付');
			// 	this.$refs.popup4.open()
			// },
			// 关闭支付弹窗
			pop4Close() {
				this.$refs.popup4.close()
			},
			// 再付款之前进行选择
			paychoose() {
				uni.showModal({
					title: "提示",
					content: "请选择支付方式",
					cancelText: '余额支付',
					confirmText: '微信支付',
					cancelColor: "#333",
					confirmColor: '#22B591',
					success: res => {
						if (res.confirm) {
							console.log('用户微信支付');
							this.pay()
						} else if (res.cancel) {
							console.log('用户余额支付');
							this.yuepay()

							this.$refs.popup4.close()
						}
					}
				})

			},
			yuepay() {
				this.$request('order/pay/' + this.choosecancelitem.group_order_id, {
					type: 'balance'
				}).then(res => {
					if (res.status == 200) {
						uni.hideLoading()
						uni.showToast({
							title: "支付成功",
							icon: "none"
						})
						this.page = 1
						this.choosecancelitem = ''
						this.radiovalue1 = ''
						this.getlist(this.page)

					}
				})
			},
			// 付款
			pay() {

				uni.showLoading({
					mask: true,
					title: "支付中"
				})
				this.$request('order/pay/' + this.choosecancelitem.group_order_id, {
					type: 'routine'
				}).then(res => {
					if (res.status == 200) {
						uni.hideLoading()

						this.paying(res.data.result.config)

					}
				})


				this.$refs.popup4.close()
			},
			paying(e) {

				let that = this
				let orderInfo = {
					timeStamp: e.timestamp,
					nonceStr: e.nonceStr,
					package: e.package,
					signType: e.signType,
					paySign: e.paySign,
				}
				wx.requestPayment({
					...orderInfo,

					success: (res) => {
						uni.showToast({
							title: "支付成功",
							icon: "none"
						})
						this.page = 1
						this.choosecancelitem = ''
						this.radiovalue1 = ''
						this.getlist(this.page)
					},
					fail(e) {

						wx.showToast({
							title: '支付失败',
							icon: 'none'
						})

					}
				})

			},
			// 修改配送时间
			updateDateOrder(id) {
				this.chooseid = id
				this.$refs.popup3.open()
			},
			// 切换配送时间
			checkDate(index) {
				this.activeT = index
			},
			// 选择配送时间
			// chooseTimes(index) {
			// 	this.active2 = index;
			// 	this.order.time = this.date_list[this.active] + this.times_list[this.active2].name
			// 	this.$refs.popup3.close();
			// },
			// 选择配送时间
			chooseTimes(index) {
				this.active2 = index;
				if (this.times_list[index].isValid == false && this.date_list[this.activeT] == '今天') {
					this.$showToast('已过时间')
					return;
				}
				let date
				if (this.date_list[this.activeT] == '今天') {
					date = this.getDay(0, 3600000)
				} else {
					date = this.getDay(1, 3600000)
				}

				let delivery_start_date = date + ' ' + this.times_list[this.active2].tips + this.times_list[this.active2]
					.start
				let delivery_end_date = date + ' ' + this.times_list[this.active2].tips + this.times_list[this.active2].end
				let delivery_time_scope = this.times_list[this.active2].start + '-' + this.times_list[this.active2].end

				let data = {
					group_order_id: this.chooseid,
					delivery_start_date,
					delivery_end_date,
					delivery_time_scope
				}
				uni.showModal({
					title: '提示',
					content: '是否更改时间为' + this.date_list[this.activeT] + delivery_time_scope,
					success: res => {
						if (res.confirm) {
							uni.showLoading({
								mask: true
							})
							this.$request('order/change_delivery_time', data).then(res => {
								if (res.status == 200) {
									uni.hideLoading()
									this.$refs.popup3.close()
									this.page = 1
									this.chooseid = ''
									this.getlist(this.page)

								}
							})
						} else if (res.cancel) {

						}
					}
				});







			},

			// 关闭配送时间弹窗
			pop3Close() {
				this.$refs.popup3.close()
			},
			// 催单
			reminderOrder2(id) {
				// this.chooseid = id
				// console.log('xdsdf')
				this.$request('user/urgeOrderTask', {
					content: '',
					order_id: id
				}).then(res => {
					if (res.status == 200) {
						uni.hideLoading()
						this.cuifocontent = res.data.content
						this.cuifotitle = res.data.title
						this.$refs.popup7.open()
						this.page = 1

						this.getlist(this.page)

					}
				})
			},
			reminderOrder(id) {


			},
			// 关闭催单弹窗
			pop7Close() {
				this.$refs.popup7.close()
				this.$refs.popup22.close()
			},
			// 去评价
			goEvaluation(id) {
				console.log('去评价');
				uni.navigateTo({
					url: '/pages/client/order/evaluation/evaluation?id=' + id + '&orign=' + this.orign
				})
			},
			// 申请售后
			goAfterSales(item) {
				uni.navigateTo({
					url: `/pages/client/order/apply-shouhou/apply-shouhou?group_order_id=${item.group_order_id}`
				})
			},
			// 再来一单
			againOrder(item) {
				let data = {
					data: []
				}
				item.goods.forEach(cart => {
					data.data.push({
						product_id: cart.product_id,
						product_attr_unique: cart.product_sku,
						cart_num: cart.product_num
					})
				})
				let cartIds = []
				let cartS = []
				// getCartApi
				console.log(data, '再来一单');
				againApi(data).then(res => {
					cartIds = res.data.cart_id
					return orderCheckApi({
						address_id: "",
						takes: [],
						use_integral: false,
						cart_id: cartIds
					})
				}).then(res => {
					res.data.order.forEach(merOrder => {
						cartS.push(...merOrder.list)
					})
					Cache.set('cartToPayCheck', cartS)
					uni.navigateTo({
						url: '/pages/client/order/order-sure/order-sure?isagain=1',
						fail: (err) => {
							console.log(err)
						}
					})
				}).catch(err => {
					console.log(err)
				})
				// againApi(data).then(res => {
				// 	cartIds = res.data.cart_id
				// 	return getCartApi({
				// 		is_new: 22
				// 	})
				// }).then(res => {
				// 	res.data.list.forEach(merCart => {
				// 		merCart.list.forEach(cart => {
				// 			console.log(cart)
				// 			if (cartIds.indexOf(cart.cart_id) != -1) {
				// 				console.log("?????????//")
				// 				cartS.push(cart)
				// 			}
				// 		})
				// 	})
				// 	Cache.set('cartToPayCheck', cartS)
				// 	// uni.navigateTo({
				// 	// 	url: '/pages/client/order/order-sure/order-sure',
				// 	// 	fail: (err) => {
				// 	// 		console.log(err)
				// 	// 	}
				// 	// })
				// }).catch(err => {
				// 	console.log(err)
				// })

			},
			// 申请开票
			applyTicket(index) {
				let list = this.list
				let item = list[index]
				let group_order_id = item.group_order_id
				let arr = []
				item.orderList.forEach(item => {
					arr.push(item.order_id)
				})
				let order_ids = JSON.stringify(arr)


				uni.navigateTo({
					url: '/pages/client/order/apply-kaipiao/apply-kaipiao?group_order_id=' + group_order_id +
						'&order_ids=' + order_ids
				})
			},
			// 开票历史
			ticketHistory(id) {
				console.log('开票历史');
				uni.navigateTo({
					url: '/pages/client/order/history-kaipiao/history-kaipiao'
				})
			},
			// 更多
			openMore(index) {
				this.list[index].show_more = !this.list[index].show_more;
				this.activeT = index;
				this.is_mask = true;
			},
			// 取消更多
			cancelMore() {
				this.list.forEach(item => {
					item.show_more = false
				})
				this.is_mask = false;
			}
		}
	}
</script>

<style lang="scss" scoped>
	.box {
		position: relative;

		.red {
			color: #F83535;
		}

		.tab {
			padding: 0 10rpx 12rpx;
		}

		.none {
			text-align: center;

			.none-img {
				margin: 95rpx auto 20rpx;
				width: 306rpx;
				height: 352rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.none-desc {
				margin-top: 20rpx;
			}

			.none-btn {
				margin: 130rpx auto 0;
				width: 300rpx;
				height: 100rpx;
				line-height: 100rpx;
				text-align: center;
				font-size: 32rpx;
				color: #fff;
				background: linear-gradient(64deg, #2BCCA5, #22B591);
				box-shadow: 0rpx 4rpx 6rpx 0rpx rgba(20, 187, 146, 0.4);
				border-radius: 10rpx;
			}
		}

		.content {
			min-height: calc(100vh - 100rpx);
			padding: 0 30rpx 80rpx;
			background-color: #F5F5F5;
			overflow: hidden;
			box-sizing: border-box;

			.card {
				margin: 20rpx auto;
				padding: 20rpx 30rpx;
				width: 690rpx;
				// height: 380rpx;
				background: #FFFFFF;
				border-radius: 20rpx;
				box-sizing: border-box;

				.two {
					margin: 13rpx 0;
					padding: 18rpx;
					background: #F7F7F7;

					&>view:nth-child(2) {
						margin-top: 6rpx;
					}
				}

				.three {
					margin: 10rpx 0 18rpx;
				}

				.four {
					.goods-img {
						width: 500rpx;
						overflow: hidden;

						&>view:nth-child(1) {
							width: 440rpx;
							overflow: hidden;
						}

						.goods-img2 {
							margin-right: 10rpx;
						}

						image {
							width: 100rpx;
							height: 100rpx;
							border-radius: 10rpx;
						}
					}

					.dot {
						flex-shrink: 0;
						margin: 0 20rpx;
						width: 30rpx;
						height: 8rpx;

						image {
							width: 100%;
							height: 100%;
						}
					}

					.four-r {
						flex: 1;
						text-align: right;

					}
				}

				.four+.two {
					margin: 20rpx 0 11rpx;
				}

				.five {
					margin-top: 22rpx;
					justify-content: flex-end;
					flex-wrap: wrap;

					&>view {
						flex-shrink: 0;
						width: 160rpx;
						height: 60rpx;
						line-height: 60rpx;
						font-size: 24rpx;
						text-align: center;
						background: #FFFFFF;
						border: 1rpx solid #CCCCCC;
						border-radius: 10rpx;
						margin-bottom: 10rpx;
					}

					&:not(:nth-child(1))>view {
						margin-left: 20rpx;
					}

					.state1 {
						background: #F83535;
						border: 1rpx solid #F83535;
						color: #fff;
					}

					.state2 {
						background: linear-gradient(64deg, #2BCCA5, #22B591);
						box-shadow: 0rpx 4rpx 6rpx 0rpx rgba(20, 187, 146, 0.4);
						border: 1rpx solid #14BB92;
						color: #fff;
					}

					.state3 {
						background: #F5F5F5;
						border: 1rpx solid #F5F5F5;
						color: #999;
					}

					.more {
						position: relative;
						width: 84rpx;
						border: none;
						text-align: left;
						color: #999;

						.sanjiao {
							left: 10rpx;
							bottom: -4rpx;
							position: absolute;
							width: 0;
							height: 0;
							border-left: 15rpx solid transparent;
							border-right: 15rpx solid transparent;
							border-bottom: 25rpx solid #fff;
							z-index: 12;
						}

						.more2 {
							position: absolute;
							bottom: -125rpx;
							left: -10rpx;
							width: 190rpx;
							height: 130rpx;
							background: #FFFFFF;
							box-shadow: 0rpx 1rpx 32rpx 4rpx rgba(176, 177, 178, 0.36);
							border-radius: 4rpx;
							z-index: 15;

							&>view {
								height: 65rpx;
								color: #333;
								line-height: 65rpx;
								text-align: center;
							}

							&>view:not(:last-child) {
								border-bottom: 1rpx solid #eee;
							}
						}
					}
				}
			}
		}

		.mask {
			position: fixed;
			left: 0;
			top: 0;
			width: 750rpx;
			height: 100vh;
			background: rgba(255, 255, 255, 0);
			z-index: 14;
		}

		// 配送时间弹窗
		.pop3 {
			position: relative;
			width: 750rpx;
			height: 540rpx;
			background: #FFFFFF;
			border-radius: 20rpx 20rpx 0rpx 0rpx;
			overflow: hidden;

			.green2 {
				color: #109C7A;
			}

			.pop3-close {
				position: absolute;
				top: 15rpx;
				right: 30rpx;
				width: 38rpx;
				height: 38rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.pop3-title {
				margin-top: 36rpx;
			}

			.pop3-box {
				height: 458rpx;
				font-size: 28rpx;

				.pop3-left {
					width: 140rpx;
					height: 458rpx;
					background-color: #FAFAFA;

					&>view {
						padding: 30rpx 0;
					}
				}

				.pop3-right {
					flex: 1;
					height: 458rpx;
					overflow-y: auto;

					&>view {
						padding: 30rpx 30rpx;
					}

					.pop3-img {
						width: 38rpx;
						height: 34rpx;

						image {
							width: 100%;
							height: 100%;
						}
					}
				}
			}
		}

		// 支付弹窗
		.pop4 {
			position: relative;
			width: 750rpx;
			height: 670rpx;
			padding: 0 30rpx;
			background: #FFFFFF;
			border-radius: 20rpx 20rpx 0rpx 0rpx;
			overflow: hidden;
			box-sizing: border-box;

			.pop4-close {
				position: absolute;
				top: 15rpx;
				right: 30rpx;
				width: 38rpx;
				height: 38rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.pop4-title {
				padding: 30rpx 0;
			}

			.pop4-desc {
				padding: 16rpx 20rpx;
				color: #F45E14;
				font-size: 24rpx;
				background: #FAFAFA;
			}

			.pop4-list {
				height: 370rpx;
				overflow-y: auto;

				&>view {
					padding-top: 40rpx;
				}
			}

			.pop4-btn {
				width: 750rpx;
				height: 140rpx;
				background: #FFFFFF;
				font-size: 32rpx;
				color: #fff;
				text-align: center;

				&>view {
					width: 335rpx;
					height: 100rpx;
					line-height: 100rpx;
					background: linear-gradient(64deg, #7AD9C3, #70D5BD);
					border-radius: 50rpx 0rpx 0rpx 50rpx;
				}

				&>view:nth-child(2) {
					background: linear-gradient(64deg, #2BCCA5, #22B591);
					border-radius: 0rpx 50rpx 50rpx 0rpx;
				}
			}
		}

		// 取消订单原因弹窗
		.pop6 {
			position: relative;
			width: 620rpx;
			background: #FFFFFF;
			border-radius: 20rpx;
			overflow: hidden;
			box-sizing: border-box;

			.pop6-title {
				padding: 36rpx 0;
			}

			.pop6-list {
				// height: 400rpx;
				padding: 0 40rpx;
			}

			.pop6-btn {
				border-top: 1rpx solid #eee;
				height: 90rpx;

				&>view {
					width: 50%;
					line-height: 90rpx;
				}

				&>view:nth-child(1) {
					border-right: 1rpx solid #eee;
				}
			}
		}

		// 催单弹窗
		.pop7 {
			width: 490rpx;
			height: 590rpx;
			padding: 30rpx 0;
			background: #FFFFFF;
			border-radius: 48rpx;
			box-sizing: border-box;

			.pop7-img {
				margin: 0 auto;
				width: 455rpx;
				height: 455rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.tr {
				margin-top: -154rpx;

				.pop7-desc {
					margin: 20rpx 0 45rpx;
				}

				.pop7-btn {
					margin: 0 auto;
					width: 300rpx;
					height: 80rpx;
					color: #fff;
					font-size: 30rpx;
					line-height: 80rpx;
					background: linear-gradient(64deg, #2BCCA5, #22B591);
					border-radius: 40rpx;
				}
			}
		}
	}
</style>
